package appx.craft.droid.ui;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import appx.craft.droid.R;
import appx.craft.droid.utils.Constance;
import appx.craft.droid.utils.Log;
import appx.craft.droid.utils.UtilityHelper;

/**
 *This class will help to show share photo for add caption for image. 
 *
 */

public class SharePhotoCaptureActivity extends FragmentActivity {

	private final String TAG = SharePhotoCaptureActivity.class
			.getCanonicalName();
	private String imagePath;
	private ImageView image_share_photo;
	private Button btn_share_photo;
	private EditText mCaptionText;
	private LinearLayout layout_facebook_toggle;
	private InputMethodManager inputMethodManager;
	private ToggleButton toggel_onoff;
	@Override
	protected void onCreate(Bundle saveInstance) {
		super.onCreate(saveInstance);
		Log.d(TAG, "[onCreate ]");
		setContentView(R.layout.activity_share_picture);
		imagePath = getIntent().getStringExtra(Constance.INTENT_KEY_IMAGE_PATH);
		if (!imagePath.equals("")) {
			Toast.makeText(getApplicationContext(), imagePath,
					Toast.LENGTH_LONG).show();
		}

		inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);

		image_share_photo = (ImageView) findViewById(R.id.image_share_photo);
		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				
				image_share_photo.post(new Runnable() {

					@Override
					public void run() {
						image_share_photo.setImageBitmap(UtilityHelper.decodeSampledBitmapFromResource(imagePath,150, 150));
					}
				});
				
			}
		}, 1000);
		

		mCaptionText = (EditText) findViewById(R.id.editText_caption);
		btn_share_photo = (Button)findViewById(R.id.btn_green_share);
		btn_share_photo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				inputMethodManager.hideSoftInputFromWindow(mCaptionText.getApplicationWindowToken(), 0);
				if (!imagePath.equals("")) 
				{
					
					Intent mIntent = new Intent();
					mIntent.putExtra(Constance.INTENT_KEY_IMAGE_PATH,imagePath);
					mIntent.putExtra(Constance.INTENT_CAPTION,mCaptionText.getText().toString());
					setResult(RESULT_OK,mIntent);
					finish();
				}
			}
		});
		
		toggel_onoff = (ToggleButton)findViewById(R.id.toggel_onoff);
		toggel_onoff.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View view) {
				  // Is the toggle on?
	            boolean on = ((ToggleButton) view).isChecked();
	            
	            if (on) {
	                // Enable vibrate
	                Toast.makeText(getApplicationContext(), "on", Toast.LENGTH_SHORT).show();
	            } else {
	                // Disable vibrate
	                Toast.makeText(getApplicationContext(), "off", Toast.LENGTH_SHORT).show();
	            }
			}
		});
		
		layout_facebook_toggle = (LinearLayout) findViewById(R.id.layout_facebook_toggle);
		final ImageView mFBView = (ImageView) layout_facebook_toggle
				.findViewById(R.id.image_icon_facebook);
		final TextView mTextView = (TextView) layout_facebook_toggle
				.findViewById(R.id.textview_text_facebook);
		mFBView.setBackgroundDrawable(getResources().getDrawable(
				R.drawable.upload_glyph_facebook_selected));
		mTextView.setTextColor(Color.parseColor("#2477ba"));

	}

	@Override
	protected void onStart() {
		super.onStart();
		Log.d(TAG, "[onStart ]");
	}

	@Override
	protected void onStop() {
		super.onStop();
		Log.d(TAG, "[onStop]");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Log.d(TAG, "[onDestroy]");
	}

	@Override
	protected void onPause() {
		super.onPause();
		Log.d(TAG, "[onPause]");
	}

}
